Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
Probando btn click con Jasmine, obteniendo "No se pueden leer las propiedades de nulo (leyendo 'clic')"

Estoy probando la funcionalidad de dos clics de botón y si se abre o no un modal como resultado.

He realizado varias variaciones para probar estos clics en Jasmine y no estoy seguro de cómo identificar la causa de este error o cómo mitigarlo:

 TypeError: Cannot read properties of null (reading 'click')

componente.spec.ts

 describe('MyComponent', () => { let component: MyComponent; let fixture: ComponentFixture<MyComponent>; beforeEach(() => { fixture = TestBed.createComponent(MyComponent); component = fixture.componentInstance; fixture.detectChanges(); }); fit('can promote', () => { // ARRANGE // spyOn(component, 'doPromoteMethod'); // no changes if uncommented const dialog = TestBed.inject(MatDialog) as jasmine.SpyObj<MatDialog>; const dialogRef = TestBed.inject(MatDialogRef) as jasmine.SpyObj<MatDialogRef<any>>; dialog.open.and.returnValue(dialogRef); dialogRef.afterClosed.and.returnValue(of()); queryParams$.next({}); // ACT // 1st click evt: Ellipsis menu click (opens dropdown) // const ellipsisBtn: HTMLButtonElement = fixture.nativeElement.parentNode.querySelector('[data-atm="actions"]'); ellipsisBtn.click(); fixture.detectChanges(); // 2nd click evt: Btn click // const promoteBtn: HTMLButtonElement = fixture.nativeElement.parentNode.querySelector('[data-atm="promote"]'); promoteBtn.click(); fixture.detectChanges(); fixture.whenStable(); // ASSERT expect(dialog.open).toHaveBeenCalled; }); });

componente.html

 <ng-container matColumnDef="action"> <th mat-header-cell *matHeaderCellDef=""></th> <td mat-cell *matCellDef="let promotion"> <button mat-icon-button class="ellipsis-btn" data-atm="actions" [matMenuTriggerFor]="menu" [matMenuTriggerData]="{ 'promotion': promotion }" role="menubar"> <img src="/assets/icon/ellipsis-menu.svg" /> </button> </td> </ng-container> <mat-menu class="promotion-menu" #menu="matMenu"> <ng-template matMenuContent let-promotion="promotion"> <div class="promotion-menu"> <button *ngIf="shouldAllowPromotion(promotion)" mat-menu-item data-atm="promote" (click)="doPromoteMethod(promotion)">Do promotion</button> </div> </ng-template> </mat-menu>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No te veo burlándote de shouldAllowPromotion en ninguna parte. Es probable que el método devuelva falsy y, por lo tanto, no muestre el botón que necesita.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!